package object;

import java.util.Random;

public class Food {
    private String name;
    private int count;//份数
//构造函数
    public Food(String name) {
        this.name = name;
        Random r=new Random();//随机生成份数
        count=r.nextInt(5);
    }
    //创建sub方法
    public String  sub(){
        if (count<1) return "该食物已被吃光！";
        count--;
        return "吃了一份"+name;
    }

    /**
     * 重写父类方法
     * @return
     */
    @Override
    public String toString() {
        return "Food{" +
                "name='" + name + '\'' +
                ", count=" + count +
                '}';
    }
}
